package com.yuyou.tas.feedback.controller;

import com.yuyou.tas.feedback.service.IFeedbackService;
import com.yuyou.tas.util.bean.ReturnResult;
import com.yuyou.tas.util.tool.Webs;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotNull;
import java.util.List;

@Api(value="DataHandleController",description="操作接口")
@Validated
@RestController
@RequestMapping(value="/api/dataHandle")
public class DataHandleController extends BaseController{


    @Autowired
    private IFeedbackService feedbackService;

    @ApiOperation("反馈数据导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "baseSchoolIds", value = "校区Ids,逗号隔开", paramType = "query"),
            @ApiImplicitParam(name = "baseTrimesterId", value = "学期Id", paramType = "query", required = true),
            @ApiImplicitParam(name = "baseSectionIds", value = "年级Ids,逗号隔开", paramType = "query"),
            @ApiImplicitParam(name = "dataSubjectIds", value = "学科Ids,逗号隔开", paramType = "query")})
    @RequestMapping(value = "/feedbackExport", method = {RequestMethod.GET, RequestMethod.POST})
    public ReturnResult<String> feedbackExport(@RequestParam(value="baseSchoolIds",required = false)List<Long> baseSchoolIds,
                                               @NotNull(message = "学期 ID 不能为空") @RequestParam(value="baseTrimesterId",required = false)Long baseTrimesterId,
                                               @RequestParam(value="baseSectionIds",required = false)List<Long> baseSectionIds,
                                               @RequestParam(value="dataSubjectIds",required = false)List<Long> dataSubjectIds,
                                               HttpServletRequest request, HttpServletResponse response) {

        HSSFWorkbook feedbackExcel = feedbackService.feedbackStatis(baseSchoolIds, baseTrimesterId, baseSectionIds, dataSubjectIds);
        Webs.writeHSSFExcel(request, response, feedbackExcel , "课堂反馈表");
        return ReturnResult.success("OK");
    }
}
